package com.example.hello.client.TextBox;

import com.example.hello.BootstrapTextBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.ValueBoxBase;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(BootstrapTextBox.class)
public class BootstrapTextBoxConnector extends AbstractComponentConnector implements ValueChangeHandler<String> {

    public BootstrapTextBoxConnector() {
        getWidget().addValueChangeHandler(this);
    }

    @Override
    protected Widget createWidget() {
        return GWT.create(VBootstrapTextBox.class);
    }

    @Override
    public BootstrapTextBoxState getState() {
        return (BootstrapTextBoxState) super.getState();
    }

    @Override
    public VBootstrapTextBox getWidget() {
        return (VBootstrapTextBox) super.getWidget();
    }

    @Override
    public void onStateChanged(StateChangeEvent stateChangeEvent) {
        super.onStateChanged(stateChangeEvent);

        BootstrapTextBoxState state = getState();

        VBootstrapTextBox textBox = getWidget();

        textBox.setAlignment(ValueBoxBase.TextAlignment.valueOf(state.getAlignment()));
        textBox.setBlockLevel(state.isBlockLevel());
        textBox.setMaxLength(state.getMaxLength());
        textBox.setPlaceholder(state.getPlaceholder());
        textBox.setSize(state.getSize());
        textBox.setText(state.getText());
        textBox.setVisibleLength(state.getVisibleLength());
    }

    @Override
    public void onValueChange(ValueChangeEvent<String> event) {

    }

}